package com.youlu.campus.service.commission;

import com.youlu.campus.entity.commission.DistributorChannel;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class DistributorChannelService {

    @Autowired
    private MongoTemplate mongoTemplate;


   public DistributorChannel findById(String distributorChannelId){
       return this.mongoTemplate.findById(distributorChannelId,DistributorChannel.class);
   }

   public List<String> findDistributorChannelByDistributorChannelUserId(String distributorChannelUserId){
       Query query = new Query();
       query.addCriteria(Criteria.where("accountId").is(distributorChannelUserId));
       List<DistributorChannel> list = this.mongoTemplate.find(query, DistributorChannel.class);
       if(CollectionUtils.isEmpty(list)){
           return null;
       }
       return list.stream().map(DistributorChannel::getId).collect(Collectors.toList());
   }


}
